/*
 * @(#)InviteePickerTag
 *
 * Copyright (c) 2003 DCIVision Ltd
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of DCIVision
 * Ltd ("Confidential Information").  You shall not disclose such Confidential
 * Information and shall use it only in accordance with the terms of the license
 * agreement you entered into with DCIVision Ltd.
 */
package com.dcivision.framework.taglib.html;

import java.sql.Connection;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts.taglib.html.BaseTag;
import org.apache.struts.taglib.html.TextTag;
import org.apache.struts.util.ResponseUtils;

import com.dcivision.framework.ApplicationException;
import com.dcivision.framework.GlobalConstant;
import com.dcivision.framework.InviteesPickerManager;
import com.dcivision.framework.MessageResourcesFactory;
import com.dcivision.framework.SessionContainer;
import com.dcivision.framework.SystemParameterConstant;
import com.dcivision.framework.SystemParameterFactory;
import com.dcivision.framework.Utility;
import com.dcivision.framework.TextUtility;
import com.dcivision.framework.web.WebUtil;
import com.dcivision.user.bean.UserGroup;
import com.dcivision.user.bean.UserRecord;
import com.dcivision.user.bean.UserRole;
import com.dcivision.user.dao.UserGroupDAObject;
import com.dcivision.user.dao.UserRecordDAObject;
import com.dcivision.user.dao.UserRoleDAObject;

/**
  InviteePickerTag.java
  
  @author      Jim Zhou
  @company     DCIVision Limited
  @creation date   2006/11/24
  @version     $Revision: 1.11.4.14 $
*/
public class InviteePickerTag extends BaseTag {
  
  private static final Log log = LogFactory.getLog(InviteePickerTag.class);
  
  private int listSize = 15;
  private String name = null;
  private String propertyUser = null;
  private String propertyGroup = null;
  private String propertyRole = null;
  private String[] valueUser = null;
  private String[] valueGroup = null;
  private String[] valueRole = null;
  private String contextPath = null; 
  private String width = null;
  private String height = null;
  private String textWidth = null;
  private String suggestWidth = null;
  
  private String commonImgPath = null;
  private String languageImgPath = null;
  private SessionContainer sessionContainer = null;
  private HttpServletRequest request = null;
  private String actionMode = null;
  private String pageOffset = "15";
  private String onBlur = null;
  
  private boolean enableUser = true;
  private boolean enableGroup = true;
  private boolean enableRole = true;
  private boolean enableUserBrowsering = true;
  private Integer maxLength = null;

  public void release(){
    this.listSize = 15;
    this.name = null;
    this.propertyUser = null;
    this.propertyGroup = null;
    this.propertyRole = null;
    this.valueUser = null;
    this.valueGroup = null;
    this.valueRole = null;
    this.contextPath = null;
    this.width = null;
    this.height = null;
    this.textWidth = null;
    this.suggestWidth = null;
    this.commonImgPath = null;
    this.languageImgPath = null;
    this.actionMode = null;
    this.pageOffset = "15";
    this.onBlur = null;
    this.enableUser = true;
    this.enableGroup = true;
    this.enableRole = true;
    this.enableUserBrowsering = true;
    this.maxLength = null;
    super.release();
  }
  
  public String getOnBlur() {
    return onBlur;
  }

  public void setOnBlur(String onBlur) {
    this.onBlur = onBlur;
  }

  public InviteePickerTag() {
    super();
    if (Utility.isEmpty(this.width)){
      this.width = "550";
    }
    if (Utility.isEmpty(this.height)){
      this.height = "100";
    }
    if (Utility.isEmpty(this.textWidth)){
      this.textWidth = "320";
    }
    if (Utility.isEmpty(this.suggestWidth)){
      this.suggestWidth = this.textWidth;
    }
  }
  
  /**
   * tag start.
   * @return                 int
   */
  public int doStartTag() throws JspException{
      this.request  = (HttpServletRequest)this.pageContext.getRequest();
      this.contextPath = (String)this.pageContext.getServletContext().getAttribute(GlobalConstant.CONTEXT_PATH_KEY);
      this.sessionContainer = (SessionContainer)this.pageContext.getSession().getAttribute(GlobalConstant.SESSION_CONTAINER_KEY);
      this.actionMode = (String) request.getAttribute(GlobalConstant.ACTION_MODE);
      
      this.pageOffset = String.valueOf(this.listSize);

      if (!this.isEnableUser() && !this.isEnableGroup() && !this.isEnableRole()){
        this.setEnableUser(true);
      }
      
      if (!this.isEnableUser()){
        this.setEnableUserBrowsering(false);
      }
      
      return this.doTag();
  }
  
  /**
   * tag end.
   * @return                 int
   */
  public int doEndTag() throws JspException{
    int result = super.doEndTag();
    this.release();
    return result;
  }

  /**
   * tag body.
   * @return                 int
   */
  public int doTag() throws JspException {
    if (!GlobalConstant.NAV_MODE_VIEW.equals(this.actionMode)){
      ResponseUtils.write(pageContext, renderInputBox());
      ResponseUtils.write(pageContext, renderControlBox());
      if (isEnableUserBrowsering()) {
        renderUserBrowsing();        
        ResponseUtils.write(pageContext, renderTabViewJS());
      }
    } else {
      ResponseUtils.write(pageContext, renderView());
    }

    return TextTag.EVAL_BODY_INCLUDE;
  }
  
  public String renderView(){
    StringBuffer src = new StringBuffer();
    
    //entity data
    StringBuffer srcTemp = new StringBuffer();
    Connection conn = this.getConnection(request);
    UserRecordDAObject userRecordDAObject = new UserRecordDAObject(this.sessionContainer, conn);
    UserGroupDAObject userGroupDAObject = new UserGroupDAObject(this.sessionContainer, conn);
    UserRoleDAObject userRoleDAObject = new UserRoleDAObject(this.sessionContainer, conn);
    //StaffRecordDAObject staffRecordDAObject = new StaffRecordDAObject(this.sessionContainer, conn);
    if(valueUser!=null){
      for (int i = 0; i<this.valueUser.length; i++){
        try {
          if (Utility.isEmpty(this.valueUser[i])){
            continue;
          }
          UserRecord userRecord = (UserRecord)userRecordDAObject.getObjectByID(Integer.valueOf(this.valueUser[i]));
          //StaffRecord staffRecord = (StaffRecord)staffRecordDAObject.getObjectByUserRecordID(Integer.valueOf(this.valueUser[i]));
          srcTemp.append(this.renderEntityView(this.valueUser[i], "U", userRecord.getFullName(), userRecord.getEmail()));
        } catch (NumberFormatException e) {
          log.error(e, e);
          continue;
        } catch (ApplicationException e) {
          log.error(e, e);
          continue;
        }
      }
    }
    if(valueGroup!=null){
      for (int i = 0; i<this.valueGroup.length; i++){
        try {
          if (Utility.isEmpty(this.valueGroup[i])){
            continue;
          }
          UserGroup userGroup = (UserGroup)userGroupDAObject.getObjectByID(Integer.valueOf(this.valueGroup[i]));
          srcTemp.append(this.renderEntityView(this.valueGroup[i], InviteesPickerManager.TYPE_GROUP, userGroup.getGroupName(), null));
        } catch (NumberFormatException e) {
          log.error(e, e);
          continue;
        } catch (ApplicationException e) {
          log.error(e, e);
          continue;
        }
      }
    }
    
    if(valueRole!=null){
      for (int i = 0; i<this.valueRole.length; i++){
        try {
          if (Utility.isEmpty(this.valueRole[i])){
            continue;
          }  
          UserRole userRole = (UserRole)userRoleDAObject.getObjectByID(Integer.valueOf(this.valueRole[i]));
          srcTemp.append(this.renderEntityView(this.valueRole[i], InviteesPickerManager.TYPE_ROLE, userRole.getRoleName(), null));
        } catch (NumberFormatException e) {
          log.error(e, e);
          continue;
        } catch (ApplicationException e) {
          log.error(e, e);
          continue;
        }
      }      
    }

    String lyrBgColor = "#FFFFFF";
    if (GlobalConstant.NAV_MODE_VIEW.equals(actionMode)) {
      lyrBgColor = "#EEEEEE";
    }
    String borderW = "border-width:1px;";
    if (GlobalConstant.NAV_MODE_VIEW.equals(actionMode)) {
      borderW = "border-width:0px;";
    }
    
    src.append("<div class=\"div-1-d\"  id='" + this.name + "_block' name='" + this.name + "_block' style=' overflow:auto; " + borderW + " height:" + this.height + "px; width:" + this.width + "px;' >\n");
    src.append("  <span id='" + this.name + "_entity_container'>\n");
    src.append(srcTemp.toString());
    src.append("  </span>\n");
    src.append("</div>\n");
    
    return src.toString();
  }
  
  public String renderEntityView(String id, String type, String entityName, String email){
    StringBuffer src = new StringBuffer();
    
    String imgTag = "";
    if (InviteesPickerManager.TYPE_GROUP.equals(type)){
      imgTag = " <img src='" + WebUtil.getImage(pageContext.getRequest(), "IconGroup.gif")+"'/>";
    } else if (InviteesPickerManager.TYPE_ROLE.equals(type)){
      imgTag = " <img src='" + WebUtil.getImage(pageContext.getRequest(), "IconRole.gif")+"'/>";
    } else {
      imgTag = " <img src='" + WebUtil.getImage(pageContext.getRequest(), "IconUser.gif")+"'/>";
    }

    src.append("<span id='" + this.name + "_" + type + "_" + id + "' ");
    if (!Utility.isEmpty(email)){
      src.append(" title='" + email + "' "); 
    }
    src.append("  name=" + this.name + "_" + type + " ");
    src.append(" >\n");

    src.append(imgTag);
    src.append(entityName);
    src.append("</span>\n");
    
    return src.toString();
  }


  protected static String renderOptionArray(String id, String type, String name, String email){
    StringBuffer srcTemp = new StringBuffer();
    srcTemp.append("[");
    srcTemp.append(id);
    srcTemp.append(",'");     
    srcTemp.append(type);
    srcTemp.append("','");     
    srcTemp.append(TextUtility.escapeJSString(name));
    srcTemp.append("','");     
    if(email==null){ 
      email="";
    }
    srcTemp.append(email);
    srcTemp.append("']"); 
    return srcTemp.toString();
  }
  /**
   * render input box html.
   * @return                 String
   */
  public String renderInputBox(){
    StringBuffer src = new StringBuffer();
    
    /*
    StringBuffer usersID = new StringBuffer();
    StringBuffer groupsID = new StringBuffer();
    StringBuffer rolesID = new StringBuffer();
    */
    StringBuffer options = new StringBuffer();

    Connection conn = this.getConnection(request);
    UserRecordDAObject userRecordDAObject = new UserRecordDAObject(this.sessionContainer, conn);
    UserGroupDAObject userGroupDAObject = new UserGroupDAObject(this.sessionContainer, conn);
    UserRoleDAObject userRoleDAObject = new UserRoleDAObject(this.sessionContainer, conn);    

    if (!Utility.isEmpty(this.valueUser)){
      for(int i=0;i<this.valueUser.length;i++){                
        try{
          UserRecord userRecord = (UserRecord)userRecordDAObject.getObjectByID(Integer.valueOf(this.valueUser[i]));        
          if(options.length()>0){ 
            options.append(","); 
          }
          options.append(this.renderOptionArray(this.valueUser[i], "U", userRecord.getFullName(), userRecord.getEmail()));                  
        } catch (Exception e) {          
          continue;
        }        
      }
    }
    if (!Utility.isEmpty(this.valueGroup)){
      for(int i=0;i<this.valueGroup.length;i++){      
        try{
          UserGroup userGroup = (UserGroup)userGroupDAObject.getObjectByID(Integer.valueOf(this.valueGroup[i]));
          if(options.length()>0){ 
            options.append(","); 
          }          
          options.append(this.renderOptionArray(this.valueGroup[i], InviteesPickerManager.TYPE_GROUP, userGroup.getGroupName(), null));        
        } catch (Exception e) {          
          continue;
        }          
      }
    }

    if (!Utility.isEmpty(this.valueRole)){
      for(int i=0;i<this.valueRole.length;i++){
        try{        
          UserRole userRole = (UserRole)userRoleDAObject.getObjectByID(Integer.valueOf(this.valueRole[i]));
          if(options.length()>0){ 
            options.append(","); 
          }          
          options.append(this.renderOptionArray(this.valueRole[i], InviteesPickerManager.TYPE_ROLE, userRole.getRoleName(), null));
        } catch (Exception e) {          
          continue;
        }           
      }
    }
   
    String lyrBgColor = "#FFFFFF";
    if (GlobalConstant.NAV_MODE_VIEW.equals(actionMode)) {
      lyrBgColor = "#EEEEEE";
    }
    
    String display = "";
    if (GlobalConstant.NAV_MODE_VIEW.equals(actionMode)) {
      display = "none";
    }
    String borderW = "border-width:1px;";
    if (GlobalConstant.NAV_MODE_VIEW.equals(actionMode)) {
      borderW = "border-width:0px;";
    }
    
    String strOnBlur = "";
    if (!Utility.isEmpty(this.getOnBlur())) {
      strOnBlur = " onblur=\"" + this.getOnBlur() + "\" ";
    }
    
    src.append(
        "<div class=\"clearfix\">" +
        "<div class=\"div-1-d\" id=\"" + getName() + "_block\" name=\"" + getName() + "_block\" style=\"background-color:" + lyrBgColor + "; " + borderW + " height:" + getHeight() + "px; width:" + getWidth() + "px;\">\n" +
        "<span id='" + getName() + "_entity_container'></span>\n" +
        "<span id='" + getName() + "_Input' name='" + getName() + "_Input' style='display:" + display + ";'>\n" +
        "<input id='" + getName() + "_Input_text' name='" + getName() + "_Input_text' type='text' " + strOnBlur + " class='form-inviteePicker-inputText' style='width:" + getTextWidth() + "px;'/>\n" +
        "</span>\n" +
        "</div>\n"
        );
    if (isEnableUserBrowsering()) {
      src.append(
          "<div class=\"div-1-c\">" +
          "<img src='" + WebUtil.getImage(pageContext.getRequest(), "IconSearchUser.gif")+"' onclick=\"" + this.name + "_popupUserBrowsering();\" class='form-inviteePicker-imgButton' align=absMiddle border=0 />\n" +
          "</div>"
          );
    }
    src.append(
        "</div>"
        );
    
    src.append("<div class=\"suggestValueContainer\" id='" + this.name + "_Input_text_update' style='width:" + this.suggestWidth + "px;'>\n");
    src.append("</div>\n");
    src.append("<script language='javascript'> \n");
    src.append("<!--\n");
    src.append("  new Autocompleter.InviteePicker('" + this.name + "_Input_text','" + this.name + "_Input_text_update','" + this.name + "','" + this.contextPath + "','" + this.propertyUser + "','" + this.propertyGroup + "','" + this.propertyRole + "',updateList, [" + options.toString() + "], '" + actionMode + "' ," + this.getMaxLength() + " ,{fullSearch:true,choices:" + this.listSize + "});  \n");
    src.append("\n");
    src.append("  function updateList(autocompleter, token) {\n");
    src.append("    var key = document.getElementById('" + this.name + "_Input_text').value;\n");
    src.append("    var choices = " + this.listSize + ";\n");
    src.append("    var enableUser = " + this.isEnableUser() + ";\n");
    src.append("    var enableGroup = " + this.isEnableGroup() + ";\n");
    src.append("    var enableRole = " + this.isEnableRole() + ";\n");
    src.append("    var expectUserIDs = [];\n");
    src.append("    var expectGroupIDs = [];\n");
    src.append("    var expectRoleIDs = []; \n");
    src.append("    \n");

    src.append("    if (document.getElementsByName('" + this.propertyUser + "')){\n");
    src.append("      for(var i = 0; i < document.getElementsByName('" + this.propertyUser + "').length; i++){\n");
    src.append("        expectUserIDs.push(document.getElementsByName('" + this.propertyUser + "')[i].value);\n");
    src.append("      }\n");
    src.append("    }\n");
    src.append("    if (document.getElementsByName('" + this.propertyGroup + "')){\n");
    src.append("      for(var i = 0; i < document.getElementsByName('" + this.propertyGroup + "').length; i++){\n");
    src.append("        expectGroupIDs.push(document.getElementsByName('" + this.propertyGroup + "')[i].value);\n");
    src.append("      }\n");
    src.append("    }\n");
    src.append("    if (document.getElementsByName('" + this.propertyRole + "')){\n");
    src.append("      for(var i = 0; i < document.getElementsByName('" + this.propertyRole + "').length; i++){\n");
    src.append("        expectRoleIDs.push(document.getElementsByName('" + this.propertyRole + "')[i].value);\n");
    src.append("      }\n");
    src.append("    }\n");

    src.append("    \n");
    src.append("    InviteePickerDWRFacade.getResultListDynamic(enableUser,enableGroup,enableRole,choices,key,expectUserIDs,expectGroupIDs,expectRoleIDs,{callback:function(data){autocompleter.setChoices(data);},errorHandler:function(message){},timeout:10000});\n");
    src.append("  }\n");
    src.append("\n");
    src.append("//-->\n");
    src.append("</script>\n");
    
    return src.toString();
  }

  /**
   * render control box html. control box contains delete functions.
   * @return                 String
   */
  public String renderControlBox(){
    StringBuffer src = new StringBuffer();
    src.append(
        "<div id='" + getName() + "_controlbox' style='display:none;position:absolute;left:0px;top:0px;'>\n" +
        "<div class=\"inviteeContextMenu\">\n" +
        "<ul>" +
        "  <li><a href='#' onclick=\"deleteEntity('" + getName() + "');\">" + MessageResourcesFactory.getMessage(sessionContainer.getSessionLocale(),"inviteepicker.remove.removeentiy") + "</a></li>" +
        "  <li><a href='#' onclick=\"deleteAll('" + getName() + "');\">" + MessageResourcesFactory.getMessage(sessionContainer.getSessionLocale(),"inviteepicker.remove.removeall") + "</a></li>" +
        "  <li><a href='#' onclick=\"closeControlBox('" + getName() + "_controlbox');return false;\">" + MessageResourcesFactory.getMessage(sessionContainer.getSessionLocale(),"common.label.close") + "</a></li>" +
        "</ul>" +
        "</div>\n" +
        "</div>\n"
        );
    
    return src.toString();
  }

  /**
   * render user browsing dialog html.
   * @return                 String
   */
  public void renderUserBrowsing() throws JspException {
    try {
      pageContext.include("/jsp/dms/InviteePickerBrowser.jsp?prefixName=" + getName() + "&pageSize=" + getListSize());
    } catch (Exception ex) {
      throw new JspException("Error occurs at render invitee picker viewer!", ex);
    }
  }

  /**
   * render group/role/staff hierarchy tabs html.
   * @return                 String
   */
  public String renderTabs(){
    StringBuffer src = new StringBuffer();

    src.append("    <table class='form-inviteePicker-tabs' height=22 width=300 border=0 cellpadding='0' cellspacing='0'>\n");
    src.append("    <tbody>\n");
    src.append("      <tr>\n");
    src.append("        <td>\n");
    src.append("          <table height='100%' border='0' width='90' cellpadding='0' cellspacing='0' onclick=showInviteePickerTabs('" + this.name + "','Group') >\n");
    src.append("          <tbody>\n");
    src.append("            <tr>\n");
    src.append("              <TD width=5><IMG src='" + WebUtil.getImage(pageContext.getRequest(), "LayoutWhiteTabLeft.gif")+"' align=absMiddle border=0 /></TD>\n");
    src.append("              <TD id='" + this.name + "_tab_group_font' class='form-inviteePicker-tab-button' vAlign=center align=middle width=80 background=" + WebUtil.getImage(pageContext.getRequest(), "LayoutWhiteTabBg.gif")+">Group</TD>\n");
    src.append("              <TD width=5><IMG src='" + WebUtil.getImage(pageContext.getRequest(), "LayoutWhiteTabRight.gif")+"' align=absMiddle border=0 /></TD>\n");
    src.append("            </tr>\n");
    src.append("          </tbody>\n");
    src.append("          </table>\n");
    src.append("        </td>\n");
    src.append("        <td>\n");
    src.append("          <table height='100%' border='0' width='80' cellpadding='0' cellspacing='0' onclick=showInviteePickerTabs('" + this.name + "','Role') >\n");
    src.append("          <tbody>\n");
    src.append("            <tr>\n");
    src.append("              <TD width=5><IMG src='" + WebUtil.getImage(pageContext.getRequest(), "LayoutWhiteTabLeft.gif")+"' align=absMiddle border=0 /></TD>\n");
    src.append("              <TD id='" + this.name + "_tab_role_font' class='form-inviteePicker-tab-button2' vAlign=center align=middle width=70 background=" + WebUtil.getImage(pageContext.getRequest(), "LayoutWhiteTabBg.gif")+">Role</TD>\n");
    src.append("              <TD width=5><IMG src='" + WebUtil.getImage(pageContext.getRequest(), "LayoutWhiteTabRight.gif")+"' align=absMiddle border=0 /></TD>\n");
    src.append("            </tr>\n");
    src.append("          </tbody>\n");
    src.append("          </table>\n");
    src.append("        </td>\n");
    src.append("        <td>\n");
    src.append("          <table height='100%' border='0' width='130' cellpadding='0' cellspacing='0' onclick=showInviteePickerTabs('" + this.name + "','StaffHierarchy') >\n");
    src.append("          <tbody>\n");
    src.append("            <tr>\n");
    src.append("              <TD width=5><IMG src='" + WebUtil.getImage(pageContext.getRequest(), "LayoutWhiteTabLeft.gif")+"' align=absMiddle border=0 /></TD>\n");
    src.append("              <TD id='" + this.name + "_tab_staffhierarchy_font' class='form-inviteePicker-tab-button2' vAlign=center align=middle width=120 background=" + WebUtil.getImage(pageContext.getRequest(), "LayoutWhiteTabBg.gif")+">Staff Hierarchy</TD>\n");
    src.append("              <TD width=5><IMG src='" + WebUtil.getImage(pageContext.getRequest(), "LayoutWhiteTabRight.gif")+"' align=absMiddle border=0 /></TD>\n");
    src.append("            </tr>\n");
    src.append("          </tbody>\n");
    src.append("          </table>\n");
    src.append("        </td>\n");
    src.append("      </tr>\n");
    src.append("    </tbody>\n");
    src.append("    </table>\n");
    src.append("\n");
    
    return src.toString();
  }
  
  /**
   * render group/role/staff hierarchy view's common javascript function.
   * @return                 String
   */
  public String renderTabViewJS(){
    StringBuffer src = new StringBuffer();

    src.append("    <script language='javascript'>\n");
    src.append("    <!--\n");
    src.append("      dojo.require('dojo.widget.Dialog');\n");
    src.append("      dojo.require('dojo.widget.Button');\n");
    src.append("      var " + this.name + "_group_tree_selected = null;\n");
    src.append("      var " + this.name + "_role_tree_selected = null;\n");
    src.append("      var " + this.name + "_staffhierarchy_tree_selected = null;\n");
    src.append("      var " + this.name + "_selected_users_cache = [];\n");
    src.append("      var " + this.name + "_selected_users_oldcache = [];\n");
    src.append("      var " + this.name + "_selected_users_name_cache = [];\n");
    src.append("      var " + this.name + "_selected_users_email_cache = [];\n");
    src.append("      var " + this.name + "_group_key = '';\n");
    src.append("      var " + this.name + "_role_key = '';\n");
    src.append("      var " + this.name + "_staffhierarchy_key = '';\n");
    src.append("      var " + this.name + "_staffhierarchy_hierarchy = '';\n");
    
    src.append("      var " + this.name + "_selected_groups_cache = [];\n");
    src.append("      var " + this.name + "_selected_groups_oldcache = [];\n");
    src.append("      var " + this.name + "_selected_groups_name_cache = [];\n");
    src.append("      var " + this.name + "_selected_roles_cache = [];\n");
    src.append("      var " + this.name + "_selected_roles_oldcache = [];\n");
    src.append("      var " + this.name + "_selected_roles_name_cache = [];\n");
    
    src.append("      function " + this.name + "_InitDialogCach(){\n");
    src.append("        var users = document.getElementsByName('" + this.propertyUser + "');\n");
    src.append("        var groups = document.getElementsByName('" + this.propertyGroup + "');\n");
    src.append("        var roles = document.getElementsByName('" + this.propertyRole + "');\n");
    src.append("        for (var i = 0; i<users.length;i++){\n");
    src.append("          " + this.name + "_selected_users_cache[users[i].value] = users[i].value;\n");
    src.append("        }\n");
    src.append("        " + this.name + "_selected_users_oldcache = " + this.name + "_selected_users_cache.slice(0);\n");
    src.append("        for (var i = 0; i<groups.length;i++){\n");
    src.append("          " + this.name + "_selected_groups_cache[groups[i].value] = groups[i].value;\n");
    src.append("        }\n");
    src.append("        " + this.name + "_selected_groups_oldcache = " + this.name + "_selected_groups_cache.slice(0);\n");
    src.append("        for (var i = 0; i<roles.length;i++){\n");
    src.append("          " + this.name + "_selected_roles_cache[roles[i].value] = roles[i].value;\n");
    src.append("        }\n");
    src.append("        " + this.name + "_selected_roles_oldcache = " + this.name + "_selected_roles_cache.slice(0);\n");
    src.append("        " + this.name + "_refreshCheckBox();\n");
    src.append("      }\n");
    
    src.append("      function " + this.name + "_ReleaseCache(){\n");
    src.append("        " + this.name + "_selected_users_cache = [];\n");
    src.append("        " + this.name + "_selected_users_oldcache = [];\n");
    src.append("        " + this.name + "_selected_groups_cache = [];\n");
    src.append("        " + this.name + "_selected_groups_oldcache = [];\n");
    src.append("        " + this.name + "_selected_roles_cache = [];\n");
    src.append("        " + this.name + "_selected_roles_oldcache = [];\n");
    src.append("      }\n");
    
    src.append("      function " + this.name + "_refreshCheckBox(){\n");
    src.append("        var chk = document.getElementsByName('" + this.name + "_users_checkbox');\n");
    src.append("        var chk_group = document.getElementsByName('" + this.name + "_groups_checkbox');\n");
    src.append("        var chk_role = document.getElementsByName('" + this.name + "_roles_checkbox');\n");
    
    src.append("        var user_type_selected_all_chk = document.getElementById('" + InviteesPickerManager.TYPE_HIERARCHY +"');\n");
    src.append("        var group_type_selected_all_chk = document.getElementById('" + InviteesPickerManager.TYPE_GROUP +"');\n");
    src.append("        var role_type_selected_all_chk = document.getElementById('" + InviteesPickerManager.TYPE_ROLE +"');\n");
    src.append("        var is_user_selected_all = true;\n");
    
    src.append("        var group_selected_all_chk = document.getElementById('" + InviteesPickerManager.GROUP_VIEW +"');\n");
    src.append("        var is_group_selected_all = true;\n");
    
    src.append("        var role_selected_all_chk = document.getElementById('" + InviteesPickerManager.ROLE_VIEW +"');\n");
    src.append("        var is_role_selected_all = true;\n");
    
    src.append("        for(var i = 0; i < chk.length; i++ ) {\n");
    src.append("          if (chk[i].value == " + this.name + "_selected_users_cache[chk[i].value]){\n");
    src.append("            chk[i].checked = 'true';\n");
    src.append("          } else {\n");
    src.append("            chk[i].checked = '';\n");
    src.append("            is_user_selected_all = false;\n");
    src.append("          }\n");
    src.append("        }\n");
    
    src.append("        for(var i = 1; i < " + this.name + "_selected_users_cache.length; i++) {\n");
    src.append("          if(typeof " + this.name + "_selected_users_cache[i] != 'undefined' && " + this.name + "_selected_users_cache[i] == null) {\n");
    src.append("            is_user_selected_all = false;\n");
    src.append("            break;\n");
    src.append("          }\n");
    src.append("        }\n");
    
    src.append("        if(user_type_selected_all_chk) {\n");
    src.append("          if(is_user_selected_all) {\n");
    src.append("            user_type_selected_all_chk.checked = 'true';\n");
    src.append("            group_type_selected_all_chk.checked = 'true';\n");
    src.append("            role_type_selected_all_chk.checked = 'true';\n");
    src.append("          } else {\n");
    src.append("            user_type_selected_all_chk.checked = '';\n");
    src.append("            group_type_selected_all_chk.checked = '';\n");
    src.append("            role_type_selected_all_chk.checked = '';\n");
    src.append("          }\n");
    src.append("        }\n"); 
    
    src.append("        for(var i = 0; i < chk_group.length; i++) {\n");
    src.append("          if (chk_group[i].value == " + this.name + "_selected_groups_cache[chk_group[i].value]) {\n");
    src.append("            chk_group[i].checked = 'true';\n");
    src.append("          } else {\n");
    src.append("            chk_group[i].checked = '';\n");
    src.append("            is_group_selected_all = false;\n");
    src.append("          }\n");
    src.append("        }\n");
    
    src.append("        for(var i = 1; i < " + this.name + "_selected_groups_cache.length; i++) {\n");
    src.append("          if(typeof " + this.name + "_selected_groups_cache[i] != 'undefined' && " + this.name + "_selected_groups_cache[i] == null) {\n");
    src.append("            is_group_selected_all = false;\n");
    src.append("            break;\n");
    src.append("          }\n");
    src.append("        }\n");
    
    src.append("        if(group_selected_all_chk) {\n");
    src.append("          if(is_group_selected_all) {\n");
    src.append("            group_selected_all_chk.checked = 'true';\n");
    src.append("          } else {\n");
    src.append("            group_selected_all_chk.checked = '';\n");
    src.append("          }\n");
    src.append("        }\n"); 
    
    src.append("        for(var i = 0; i < chk_role.length; i++) {\n");
    src.append("          if (chk_role[i].value == " + this.name + "_selected_roles_cache[chk_role[i].value]) {\n");
    src.append("            chk_role[i].checked = 'true';\n");
    src.append("          } else {\n");
    src.append("            chk_role[i].checked = '';\n");
    src.append("            is_role_selected_all = false;\n");
    src.append("          }\n");
    src.append("        }\n");
    
    src.append("        for(var i = 1; i < " + this.name + "_selected_roles_cache.length; i++) {\n");
    src.append("          if(typeof " + this.name + "_selected_roles_cache[i] != 'undefined' && " + this.name + "_selected_roles_cache[i] == null) {\n");
    src.append("            is_role_selected_all = false;\n");
    src.append("            break;\n");
    src.append("          }\n");
    src.append("        }\n");
    
    src.append("        if(role_selected_all_chk) {\n");
    src.append("          if(is_role_selected_all) {\n");
    src.append("            role_selected_all_chk.checked = 'true';\n");
    src.append("          } else {\n");
    src.append("            role_selected_all_chk.checked = '';\n");
    src.append("          }\n");
    src.append("        }\n"); 
    src.append("      }\n");

    src.append("      function " + this.name + "_confirm(name){\n");
    src.append("        var ht = [];\n");
    src.append("        for (var i = 0; (i < " + this.name + "_selected_users_cache.length || i < " + this.name + "_selected_users_oldcache.length) ; i++){\n");
    src.append("          if (" + this.name + "_selected_users_cache[i] == null && " + this.name + "_selected_users_oldcache[i] == null) {\n");
    src.append("          } else if (" + this.name + "_selected_users_cache[i] != null && " + this.name + "_selected_users_oldcache[i] != null) {\n");
    src.append("          } else if (" + this.name + "_selected_users_cache[i] == null && " + this.name + "_selected_users_oldcache[i] != null) {\n");
    src.append("            document.getElementById('" + this.name + "_entity_container').removeChild(document.getElementById('" + this.name + "_U_'+" + this.name + "_selected_users_oldcache[i]));\n");
    src.append("          } else if (" + this.name + "_selected_users_cache[i] != null && " + this.name + "_selected_users_oldcache[i] == null) {\n");
    src.append("            ht.push(\"<div class='outInvitee' onmousedown=entityClick('" + this.name + "',this,event) id=" + this.name + "_U_\" + " + this.name + "_selected_users_cache[i] + \" title='\" + " + this.name + "_selected_users_email_cache[i] + \"' name=" + this.name + "_U>\");\n");
    src.append("            ht.push(\"<img src='" + WebUtil.getImage(pageContext.getRequest(), "IconUser.gif")+"'>\");\n");
    src.append("            ht.push(" + this.name + "_selected_users_name_cache[i]);\n");
    src.append("            ht.push(\"<img src='" + WebUtil.getImage(pageContext.getRequest(), "arrow_down.gif")+"'>\");\n");
    src.append("            ht.push(\"<input type=hidden value=\" + " + this.name + "_selected_users_cache[i] + \" name=" + this.propertyUser + ">\");\n");
    src.append("            ht.push(\"<input id=" + this.name + "_Input_textU\" + " + this.name + "_selected_users_cache[i] + \" type=hidden _extended='true'>\");\n");
    src.append("            ht.push(\"</div>\");\n");
    src.append("          }\n");
    src.append("        }\n");
    src.append("        for (var i = 0; (i < " + this.name + "_selected_groups_cache.length || i < " + this.name + "_selected_groups_oldcache.length) ; i++){\n");
    src.append("          if (" + this.name + "_selected_groups_cache[i] == null && " + this.name + "_selected_groups_oldcache[i] == null) {\n");
    src.append("          } else if (" + this.name + "_selected_groups_cache[i] != null && " + this.name + "_selected_groups_oldcache[i] != null) {\n");
    src.append("          } else if (" + this.name + "_selected_groups_cache[i] == null && " + this.name + "_selected_groups_oldcache[i] != null) {\n");
    src.append("            document.getElementById('" + this.name + "_entity_container').removeChild(document.getElementById('" + this.name + "_G_'+" + this.name + "_selected_groups_oldcache[i]));\n");
    src.append("          } else if (" + this.name + "_selected_groups_cache[i] != null && " + this.name + "_selected_groups_oldcache[i] == null) {\n");
    src.append("            ht.push(\"<div class='outInvitee' onmousedown=entityClick('" + this.name + "',this,event) id=" + this.name + "_G_\" + " + this.name + "_selected_groups_cache[i] + \"  name=" + this.name + "_G>\");\n");
    src.append("            ht.push(\"<img src='" + WebUtil.getImage(pageContext.getRequest(), "IconGroup.gif")+"'>\");\n");
    src.append("            ht.push(" + this.name + "_selected_groups_name_cache[i]);\n");
    src.append("            ht.push(\"<img src='" + WebUtil.getImage(pageContext.getRequest(), "arrow_down.gif") + "'>\");\n");
    src.append("            ht.push(\"<input type=hidden value=\" + " + this.name + "_selected_groups_cache[i] + \" name=" + this.propertyGroup +">\");\n");
    src.append("            ht.push(\"<input id=" + this.name + "_Input_textG\" + " + this.name + "_selected_groups_cache[i] + \" type=hidden _extends='true' >\");\n");
    src.append("            ht.push(\"</div>\");\n");
    src.append("          }\n");
    src.append("        }\n");
    src.append("        for (var i = 0; (i < " + this.name + "_selected_roles_cache.length || i < " + this.name + "_selected_roles_oldcache.length) ; i++){\n");
    src.append("          if (" + this.name + "_selected_roles_cache[i] == null && " + this.name + "_selected_roles_oldcache[i] == null) {\n");
    src.append("          } else if (" + this.name + "_selected_roles_cache[i] != null && " + this.name + "_selected_roles_oldcache[i] != null) {\n");
    src.append("          } else if (" + this.name + "_selected_roles_cache[i] == null && " + this.name + "_selected_roles_oldcache[i] != null) {\n");
    src.append("            document.getElementById('" + this.name + "_entity_container').removeChild(document.getElementById('" + this.name + "_R_'+" + this.name + "_selected_roles_oldcache[i]));\n");
    src.append("          } else if (" + this.name + "_selected_roles_cache[i] != null && " + this.name + "_selected_roles_oldcache[i] == null) {\n");
    src.append("            ht.push(\"<div class='outInvitee' onmousedown=entityClick('" + this.name + "',this,event) id=" + this.name + "_R_\" + " + this.name + "_selected_roles_oldcache[i] + \"  name=" + this.name + "_R>\");\n");
    src.append("            ht.push(\"<img src='" + WebUtil.getImage(pageContext.getRequest(), "IconRole.gif")+"'>\");\n");
    src.append("            ht.push(" + this.name + "_selected_roles_name_cache[i]);\n");
    src.append("            ht.push(\"<img src='" + WebUtil.getImage(pageContext.getRequest(), "arrow_down.gif") + "'>\");\n");
    src.append("            ht.push(\"<input type=hidden value=\" + " + this.name + "_selected_roles_cache[i] + \" name=" + this.propertyRole +">\");\n");
    src.append("            ht.push(\"<input id=" + this.name + "_Input_textR\" + " + this.name + "_selected_roles_cache[i] + \" type=hidden _extends='true' >\");\n");
    src.append("            ht.push(\"</div>\");\n");
    src.append("          }\n");
    src.append("        }\n");
    src.append("        document.getElementById('" + this.name + "_entity_container').innerHTML = document.getElementById('" + this.name + "_entity_container').innerHTML + ht.join(\"\");\n");
    src.append("        if (" + (Utility.isEmpty(this.getMaxLength())?"false":"true") + "){\n");
    src.append("          var n1=0;\n");
    src.append("          var n2=0;\n");
    src.append("          var n3=0;\n");
    src.append("          if (document.getElementsByName('" + this.getPropertyUser() + "')){\n");
    src.append("            n1 = document.getElementsByName('" + this.getPropertyUser() + "').length;\n");
    src.append("          }\n");
    src.append("          if (document.getElementsByName('" + this.getPropertyGroup() + "')){\n");
    src.append("            n2 = document.getElementsByName('" + this.getPropertyGroup() + "').length;\n");
    src.append("          }\n");
    src.append("          if (document.getElementsByName('" + this.getPropertyRole() + "')){\n");
    src.append("            n3 = document.getElementsByName('" + this.getPropertyRole() + "').length;\n");
    src.append("          }\n");
    src.append("          var n = n1 + n2 + n3;\n");
    src.append("          for (var i=0;i<n-" + this.getMaxLength() + ";i++){\n");
    src.append("            document.getElementById('" + this.name + "_entity_container').removeChild(document.getElementById('" + this.name + "_entity_container').firstChild);\n");
    src.append("          }\n");
    src.append("        }\n");
    src.append("        hideDialog(name);\n");
    src.append("        " + this.name + "_ReleaseCache();\n");
    src.append("        return null;\n");
    src.append("      }\n");
    
    src.append("      function " + this.name + "_reset(name){\n");
    src.append("        " + this.name + "_selected_users_cache = " + this.name + "_selected_users_oldcache.slice(0);\n");
    src.append("        " + this.name + "_selected_groups_cache = " + this.name + "_selected_groups_oldcache.slice(0);\n");
    src.append("        " + this.name + "_selected_roles_cache = " + this.name + "_selected_roles_oldcache.slice(0);\n");
    src.append("        " + this.name + "_refreshCheckBox();\n");
    src.append("        return null;\n");
    src.append("      }\n");
    
    src.append("      function " + this.name + "_RowDown(theRow,userId){\n");
    src.append("        if (" + this.name + "_selected_users_cache[userId] == userId){\n");
    src.append("          " + this.name + "_selected_users_cache[userId] = null;\n");
    src.append("          " + this.name + "_selected_users_name_cache[userId] = null;\n");
    src.append("          " + this.name + "_selected_users_email_cache[userId] = null;\n");
    src.append("        } else {\n");
    src.append("          " + this.name + "_selected_users_cache[userId] = userId;\n");
    src.append("          " + this.name + "_selected_users_name_cache[userId] = theRow.getAttribute('username');\n");
    src.append("          " + this.name + "_selected_users_email_cache[userId] = theRow.getAttribute('email');\n");
    src.append("        }\n");
    src.append("        " + this.name + "_refreshCheckBox();\n");
    src.append("      }\n");
    
    src.append("      function " + this.name + "_GroupRowDown(theRow,groupId){\n");
    src.append("        if (" + this.name + "_selected_groups_cache[groupId] == groupId){\n");
    src.append("          " + this.name + "_selected_groups_cache[groupId] = null;\n");
    src.append("          " + this.name + "_selected_groups_name_cache[groupId] = null;\n");
    src.append("        } else {\n");
    src.append("          " + this.name + "_selected_groups_cache[groupId] = groupId;\n");
    src.append("          " + this.name + "_selected_groups_name_cache[groupId] = theRow.getAttribute('groupname');\n");
    src.append("        }\n");
    src.append("        " + this.name + "_refreshCheckBox();\n");
    src.append("      }\n");
    
    src.append("      function " + this.name + "_RoleRowDown(theRow,roleId){\n");
    src.append("        if (" + this.name + "_selected_roles_cache[roleId] == roleId){\n");
    src.append("          " + this.name + "_selected_roles_cache[roleId] = null;\n");
    src.append("          " + this.name + "_selected_roles_name_cache[roleId] = null;\n");
    src.append("        } else {\n");
    src.append("          " + this.name + "_selected_roles_cache[roleId] = roleId;\n");
    src.append("          " + this.name + "_selected_roles_name_cache[roleId] = theRow.getAttribute('rolename');\n");
    src.append("        }\n");
    src.append("        " + this.name + "_refreshCheckBox();\n");
    src.append("      }\n");

    src.append("      function " + this.name + "_select_all(type,ele) {\n");
    src.append("        if ('" + InviteesPickerManager.TYPE_GROUP + "' == type) {\n");
    src.append("          if (ele.checked) {\n");
    src.append("            " + this.name + "_GroupSelectAll();\n");
    src.append("          } else {\n");
    src.append("            " + this.name + "_GroupSelectNone();\n");
    src.append("          }\n");
    src.append("        } else if ('" + InviteesPickerManager.TYPE_ROLE + "' == type) {\n");
    src.append("          if (ele.checked) {\n");
    src.append("            " + this.name + "_RoleSelectAll();\n");
    src.append("          } else {\n");
    src.append("            " + this.name + "_RoleSelectNone();\n");
    src.append("          }\n");
    src.append("        } else if ('" + InviteesPickerManager.TYPE_HIERARCHY + "' == type) {\n");
    src.append("          if (ele.checked) {\n");
    src.append("            " + this.name + "_StaffSelectAll();\n");
    src.append("          } else {\n");
    src.append("            " + this.name + "_StaffSelectNone();\n");
    src.append("          }\n");
    src.append("        } else if ('" + InviteesPickerManager.GROUP_VIEW + "' == type) {\n");
    src.append("          if (ele.checked) {\n");
    src.append("            " + this.name + "_GroupTabSelectAll();\n");
    src.append("          } else {\n");
    src.append("            " + this.name + "_GroupTabSelectNone();\n");
    src.append("          }\n");
    src.append("        } else if ('" + InviteesPickerManager.ROLE_VIEW + "' == type) {\n");
    src.append("          if (ele.checked) {\n");
    src.append("            " + this.name + "_RoleTabSelectAll();\n");
    src.append("          } else {\n");
    src.append("            " + this.name + "_RoleTabSelectNone();\n");
    src.append("          }\n");
    src.append("        }\n");
    src.append("      }\n");
    
    src.append("      function " + this.name + "_GroupTabSelectAll() {\n");
    src.append("        var searchName = document.getElementById(\"" + this.name + "GroupNameContain\").value;\n");
    src.append("        InviteePickerDWRFacade.getGroupRecordsAndPageInfo(searchName,1,10000,'GROUP_NAME','ASC',{callback:function(data){eval('" + this.name + "_SelectGroupAllComplete(data)');},errorHandler:function(message){eval('timeOutError(message)');},timeout:10000});\n");
    src.append("      }\n");
    
    src.append("      function " + this.name + "_GroupTabSelectNone() {\n");
    src.append("        var searchName = document.getElementById(\"" + this.name + "GroupNameContain\").value;\n");
    src.append("        InviteePickerDWRFacade.getGroupRecordsAndPageInfo(searchName,1,10000,'GROUP_NAME','ASC',{callback:function(data){eval('" + this.name + "_SelectGroupNoneComplete(data)');},errorHandler:function(message){eval('timeOutError(message)');},timeout:10000});\n");
    src.append("      }\n");
    
    src.append("      function " + this.name + "_RoleTabSelectAll() {\n");
    src.append("        var searchName = document.getElementById(\"" + this.name + "RoleNameContain\").value;\n");
    src.append("        InviteePickerDWRFacade.getRoleRecordsAndPageInfo(searchName,1,10000,'ROLE_NAME','ASC',{callback:function(data){eval('" + this.name + "_SelectRoleAllComplete(data)');},errorHandler:function(message){eval('timeOutError(message)');},timeout:10000});\n");
    src.append("      }\n");
    
    src.append("      function " + this.name + "_RoleTabSelectNone() {\n");
    src.append("        var searchName = document.getElementById(\"" + this.name + "RoleNameContain\").value;\n");
    src.append("        InviteePickerDWRFacade.getRoleRecordsAndPageInfo(searchName,1,10000,'ROLE_NAME','ASC',{callback:function(data){eval('" + this.name + "_SelectRoleNoneComplete(data)');},errorHandler:function(message){eval('timeOutError(message)');},timeout:10000});\n");
    src.append("      }\n");
    
    src.append("      function " + this.name + "_GroupSelectAll(){\n");
    src.append("        var searchName = document.getElementById(\"" + this.name + "UserNameContain\").value;\n");
    src.append("        InviteePickerDWRFacade.getUserRecordsAndPageInfo(searchName,'" + InviteesPickerManager.TYPE_GROUP + "'," + this.name + "_group_key,'',1,10000,'FULL_NAME','ASC',{callback:function(data){eval('" + this.name + "_SelectAllComplete(data)');},errorHandler:function(message){eval('timeOutError(message)');},timeout:10000});\n");
    src.append("      }\n");
    
    src.append("      function " + this.name + "_GroupSelectNone(){\n");
    src.append("        var searchName = document.getElementById(\"" + this.name + "UserNameContain\").value;\n");
    src.append("        InviteePickerDWRFacade.getUserRecordsAndPageInfo(searchName,'" + InviteesPickerManager.TYPE_GROUP + "'," + this.name + "_group_key,'',1,10000,'FULL_NAME','ASC',{callback:function(data){eval('" + this.name + "_SelectNoneComplete(data)');},errorHandler:function(message){eval('timeOutError(message)');},timeout:10000});\n");
    src.append("      }\n");
    
    src.append("      function " + this.name + "_RoleSelectAll(){\n");
    src.append("        var searchName = document.getElementById(\"" + this.name + "UserNameContain\").value;\n");
    src.append("        InviteePickerDWRFacade.getUserRecordsAndPageInfo(searchName,'" + InviteesPickerManager.TYPE_ROLE + "'," + this.name + "_role_key,'',1,10000,'FULL_NAME','ASC',{callback:function(data){eval('" + this.name + "_SelectAllComplete(data)');},errorHandler:function(message){eval('timeOutError(message)');},timeout:10000});\n");
    src.append("      }\n");
    
    src.append("      function " + this.name + "_RoleSelectNone(){\n");
    src.append("        var searchName = document.getElementById(\"" + this.name + "UserNameContain\").value;\n");
    src.append("        InviteePickerDWRFacade.getUserRecordsAndPageInfo(searchName,'" + InviteesPickerManager.TYPE_ROLE + "'," + this.name + "_role_key,'',1,10000,'FULL_NAME','ASC',{callback:function(data){eval('" + this.name + "_SelectNoneComplete(data)');},errorHandler:function(message){eval('timeOutError(message)');},timeout:10000});\n");
    src.append("      }\n");
    
    src.append("      function " + this.name + "_StaffSelectAll(){\n");
    src.append("        var searchName = document.getElementById(\"" + this.name + "UserNameContain\").value;\n");
    src.append("        InviteePickerDWRFacade.getUserRecordsAndPageInfo(searchName,'" + InviteesPickerManager.TYPE_HIERARCHY + "'," + this.name + "_staffhierarchy_key," + this.name + "_staffhierarchy_hierarchy,1,10000,'FULL_NAME','ASC',{callback:function(data){eval('" + this.name + "_SelectAllComplete(data)');},errorHandler:function(message){eval('timeOutError(message)');},timeout:10000});\n");
    src.append("      }\n");

    src.append("      function " + this.name + "_StaffSelectNone(){\n");
    src.append("        var searchName = document.getElementById(\"" + this.name + "UserNameContain\").value;\n");
    src.append("        InviteePickerDWRFacade.getUserRecordsAndPageInfo(searchName,'" + InviteesPickerManager.TYPE_HIERARCHY + "'," + this.name + "_staffhierarchy_key," + this.name + "_staffhierarchy_hierarchy,1,10000,'FULL_NAME','ASC',{callback:function(data){eval('" + this.name + "_SelectNoneComplete(data)');},errorHandler:function(message){eval('timeOutError(message)');},timeout:10000});\n");
    src.append("      }\n");

    src.append("      function " + this.name + "_SelectGroupAllComplete(datalist){\n");
    src.append("        for (var i = 0; i < datalist.length-1 ; i++){\n");
    src.append("          " + this.name + "_selected_groups_cache[datalist[i][0]] = datalist[i][0];\n");
    src.append("          " + this.name + "_selected_groups_name_cache[datalist[i][0]] = datalist[i][1];\n");
    src.append("        }\n");
    src.append("        " + this.name + "_refreshCheckBox();\n");
    src.append("      }\n");
    
    src.append("      function " + this.name + "_SelectGroupNoneComplete(datalist){\n");
    src.append("        for (var i = 0; i < datalist.length-1 ; i++){\n");
    src.append("          " + this.name + "_selected_groups_cache[datalist[i][0]] = null;\n");
    src.append("          " + this.name + "_selected_groups_name_cache[datalist[i][0]] = null;\n");
    src.append("        }\n");
    src.append("        " + this.name + "_refreshCheckBox();\n");
    src.append("      }\n");
    
    src.append("      function " + this.name + "_SelectRoleAllComplete(datalist){\n");
    src.append("        for (var i = 0; i < datalist.length-1 ; i++){\n");
    src.append("          " + this.name + "_selected_roles_cache[datalist[i][0]] = datalist[i][0];\n");
    src.append("          " + this.name + "_selected_roles_name_cache[datalist[i][0]] = datalist[i][1];\n");
    src.append("        }\n");
    src.append("        " + this.name + "_refreshCheckBox();\n");
    src.append("      }\n");
    
    src.append("      function " + this.name + "_SelectRoleNoneComplete(datalist){\n");
    src.append("        for (var i = 0; i < datalist.length-1 ; i++){\n");
    src.append("          " + this.name + "_selected_roles_cache[datalist[i][0]] = null;\n");
    src.append("          " + this.name + "_selected_roles_name_cache[datalist[i][0]] = null;\n");
    src.append("        }\n");
    src.append("        " + this.name + "_refreshCheckBox();\n");
    src.append("      }\n");
    
    src.append("      function " + this.name + "_SelectAllComplete(datalist){\n");
    src.append("        for (var i = 0; i < datalist.length-1 ; i++){\n");
    src.append("          " + this.name + "_selected_users_cache[datalist[i][0]] = datalist[i][0];\n");
    src.append("          " + this.name + "_selected_users_name_cache[datalist[i][0]] = datalist[i][1];\n");
    src.append("          " + this.name + "_selected_users_email_cache[datalist[i][0]] = datalist[i][2];\n");
    src.append("        }\n");
    src.append("        " + this.name + "_refreshCheckBox();\n");
    src.append("      }\n");
    
    src.append("      function " + this.name + "_SelectNoneComplete(datalist){\n");
    src.append("        for (var i = 0; i < datalist.length-1 ; i++){\n");
    src.append("          " + this.name + "_selected_users_cache[datalist[i][0]] = null;\n");
    src.append("          " + this.name + "_selected_users_name_cache[datalist[i][0]] = null;\n");
    src.append("          " + this.name + "_selected_users_email_cache[datalist[i][0]] = null;\n");
    src.append("        }\n");
    src.append("        " + this.name + "_refreshCheckBox();\n");
    src.append("      }\n");
    
    src.append("      function " + this.name + "_GroupTreeClick(name,spanEle,type,key,hierarchy,startOffset,pageSize,orderBy,req) {\n");
    src.append("        var gourp_user_list_id = name + \"_group_user_list\";\n");
    src.append("        if (key == null) key = '';\n");
    src.append("        if (hierarchy == null) hierarchy = '';\n");
    src.append("        document.getElementById(\"" + this.name + "UserNameContain\").value = \"\";\n");
    src.append("        InviteePickerDWRFacade.getUserRecordsAndPageInfo('',type,key,hierarchy,startOffset,pageSize,orderBy,req,{callback:function(data){eval('" + this.name + "_update_list(\\'' + gourp_user_list_id + '\\',data,\\'\\',\\'' + type + '\\',\\'' + key + '\\',\\'' + hierarchy + '\\',\\'' + startOffset + '\\',\\'' + pageSize + '\\',\\'' + orderBy + '\\',\\'' + req + '\\')');},errorHandler:function(message){eval('timeOutError(message)');},timeout:10000});\n");
    src.append("        if (" + this.name + "_group_tree_selected) {\n");
    src.append("          " + this.name + "_group_tree_selected.className = \"treeOut\";\n");
    src.append("        }\n");
    src.append("        spanEle.className = \"treeClick\";\n");
    src.append("        " + this.name + "_group_tree_selected = spanEle;\n");
    src.append("        " + this.name + "_group_key = key;\n");
    src.append("        return null;\n");
    src.append("      }\n");
    
    src.append("      function " + this.name + "_RoleTreeClick(name,spanEle,type,key,hierarchy,startOffset,pageSize,orderBy,req){\n");
    src.append("        var role_user_list_id = name + \"_role_user_list\";\n");
    src.append("        if (key == null) key = '';\n");
    src.append("        if (hierarchy == null) hierarchy = '';\n");
    src.append("        document.getElementById(\"" + this.name + "UserNameContain\").value = \"\";\n");
    src.append("        InviteePickerDWRFacade.getUserRecordsAndPageInfo('',type,key,hierarchy,startOffset,pageSize,orderBy,req,{callback:function(data){eval('" + this.name + "_update_list(\\'' + role_user_list_id + '\\',data,\\'\\',\\'' + type + '\\',\\'' + key + '\\',\\'' + hierarchy + '\\',\\'' + startOffset + '\\',\\'' + pageSize + '\\',\\'' + orderBy + '\\',\\'' + req + '\\')');},errorHandler:function(message){eval('timeOutError(message)');},timeout:10000});\n");
    src.append("        if (" + this.name + "_role_tree_selected) {\n");
    src.append("          " + this.name + "_role_tree_selected.className = \"treeOut\";\n");
    src.append("        }\n");
    src.append("        spanEle.className = \"treeClick\";\n");
    src.append("        " + this.name + "_role_tree_selected = spanEle;\n");
    src.append("        " + this.name + "_role_key = key;\n");
    src.append("        return null;\n");
    src.append("      }\n");
    
    src.append("      function " + this.name + "_StaffTreeClick(name,spanEle,type,key,hierarchy,startOffset,pageSize,orderBy,req){\n");
    src.append("        var staffhierarchy_user_list_id = name + \"_staffhierarchy_user_list\";\n");
    src.append("        if (key == null) key = '';\n");
    src.append("        if (hierarchy == null) hierarchy = '';\n");
    src.append("        document.getElementById(\"" + this.name + "UserNameContain\").value = \"\";\n");
    src.append("        InviteePickerDWRFacade.getUserRecordsAndPageInfo('',type,key,hierarchy,startOffset,pageSize,orderBy,req,{callback:function(data){eval('" + this.name + "_update_list(\\'' + staffhierarchy_user_list_id + '\\',data,\\'\\',\\'' + type + '\\',\\'' + key + '\\',\\'' + hierarchy + '\\',\\'' + startOffset + '\\',\\'' + pageSize + '\\',\\'' + orderBy + '\\',\\'' + req + '\\')');},errorHandler:function(message){eval('timeOutError(message)');},timeout:10000});\n");
    src.append("        if (" + this.name + "_staffhierarchy_tree_selected) {\n");
    src.append("          " + this.name + "_staffhierarchy_tree_selected.className = \"treeOut\";\n");
    src.append("        }\n");
    src.append("        spanEle.className = \"treeClick\";\n");
    src.append("        " + this.name + "_staffhierarchy_tree_selected = spanEle;\n");
    src.append("        " + this.name + "_staffhierarchy_key = key;\n");
    src.append("        " + this.name + "_staffhierarchy_hierarchy = hierarchy;\n");
    src.append("      }\n");
    
    src.append("      function " + this.name + "_update_group(name,searchName,type,key,hierarchy,startOffset,pageSize,orderBy,req) {\n");
    src.append("        var gourp_user_list_id = name + \"_group_user_list\";\n");
    src.append("        if (key == null) key = '';\n");
    src.append("        if (hierarchy == null) hierarchy = '';\n");
    src.append("        InviteePickerDWRFacade.getUserRecordsAndPageInfo(searchName,type,key,hierarchy,startOffset,pageSize,orderBy,req,{callback:function(data){eval('" + this.name + "_update_list(\\'' + gourp_user_list_id + '\\',data,\\'' + searchName + '\\',\\'' + type + '\\',\\'' + key + '\\',\\'' + hierarchy + '\\',\\'' + startOffset + '\\',\\'' + pageSize + '\\',\\'' + orderBy + '\\',\\'' + req + '\\')');},errorHandler:function(message){eval('timeOutError(message)');},timeout:10000});\n");
    src.append("        return null;\n");
    src.append("      }\n");
    
    src.append("      function " + this.name + "_update_role(name,searchName,type,key,hierarchy,startOffset,pageSize,orderBy,req) {\n");
    src.append("        var role_user_list_id = name + \"_role_user_list\";\n");
    src.append("        if (key == null) key = '';\n");
    src.append("        if (hierarchy == null) hierarchy = '';\n");
    src.append("        InviteePickerDWRFacade.getUserRecordsAndPageInfo(searchName,type,key,hierarchy,startOffset,pageSize,orderBy,req,{callback:function(data){eval('" + this.name + "_update_list(\\'' + role_user_list_id + '\\',data,\\'' + searchName + '\\',\\'' + type + '\\',\\'' + key + '\\',\\'' + hierarchy + '\\',\\'' + startOffset + '\\',\\'' + pageSize + '\\',\\'' + orderBy + '\\',\\'' + req + '\\')');},errorHandler:function(message){eval('timeOutError(message)');},timeout:10000});\n");
    src.append("        return null;\n");
    src.append("      }\n");
    
    src.append("      function " + this.name + "_update_staffhierarchy(name,searchName,type,key,hierarchy,startOffset,pageSize,orderBy,req) {\n");
    src.append("        var staffhierarchy_user_list_id = name + \"_staffhierarchy_user_list\";\n");
    src.append("        if (key == null) key = '';\n");
    src.append("        if (hierarchy == null) hierarchy = '';\n");
    src.append("        InviteePickerDWRFacade.getUserRecordsAndPageInfo(searchName,type,key,hierarchy,startOffset,pageSize,orderBy,req,{callback:function(data){eval('" + this.name + "_update_list(\\'' + staffhierarchy_user_list_id + '\\',data,\\'' + searchName + '\\',\\'' + type + '\\',\\'' + key + '\\',\\'' + hierarchy + '\\',\\'' + startOffset + '\\',\\'' + pageSize + '\\',\\'' + orderBy + '\\',\\'' + req + '\\')');},errorHandler:function(message){eval('timeOutError(message)');},timeout:10000});\n");
    src.append("        return null;\n");
    src.append("      }\n");
    
    src.append("      function " + this.name + "_update_group_tab(name,searchName,startOffset,pageSize,orderBy,req) {\n");
    src.append("        var group_list_id = name + \"_group_list\";\n");
    src.append("        if (searchName == null) searchName = '';\n");
    src.append("        InviteePickerDWRFacade.getGroupRecordsAndPageInfo(searchName,startOffset,pageSize,orderBy,req,{callback:function(data){eval('" + this.name + "_update_group_list(\\'' + group_list_id + '\\',data,\\'' + searchName + '\\',\\'' + startOffset + '\\',\\'' + pageSize + '\\',\\'' + orderBy + '\\',\\'' + req + '\\')');},errorHandler:function(message){eval('timeOutError(message)');},timeout:10000});\n");
    src.append("      }\n");
    
    src.append("      function " + this.name + "_update_role_tab(name,searchName,startOffset,pageSize,orderBy,req) {\n");
    src.append("        var role_list_id = name + \"_role_list\";\n");
    src.append("        if (searchName == null) searchName = '';\n");
    src.append("        InviteePickerDWRFacade.getRoleRecordsAndPageInfo(searchName,startOffset,pageSize,orderBy,req,{callback:function(data){eval('" + this.name + "_update_role_list(\\'' + role_list_id + '\\',data,\\'' + searchName + '\\',\\'' + startOffset + '\\',\\'' + pageSize + '\\',\\'' + orderBy + '\\',\\'' + req + '\\')');},errorHandler:function(message){eval('timeOutError(message)');},timeout:10000});\n");
    src.append("      }\n");
    
    src.append("      function " + this.name + "_page_select_change(tab_list_id,sel,searchName,type,key,hierarchy,startOffset,pageSize,orderBy,req){\n");
    src.append("        startOffset = (sel.value-1)*pageSize+1;\n");
    src.append("        if (key == null) key = '';\n");
    src.append("        if (hierarchy == null) hierarchy = '';\n");
    src.append("        InviteePickerDWRFacade.getUserRecordsAndPageInfo(searchName,type,key,hierarchy,startOffset,pageSize,orderBy,req,{callback:function(data){eval('" + this.name + "_update_list(\\'' + tab_list_id + '\\',data,\\'' + searchName + '\\',\\'' + type + '\\',\\'' + key + '\\',\\'' + hierarchy + '\\',\\'' + startOffset + '\\',\\'' + pageSize + '\\',\\'' + orderBy + '\\',\\'' + req + '\\')');},errorHandler:function(message){eval('timeOutError(message)');},timeout:10000});\n");
    src.append("        return null;\n");
    src.append("      }\n");
    
    src.append("      function " + this.name + "_group_page_select_change(tab_list_id,sel,searchName,startOffset,pageSize,orderBy,req){\n");
    src.append("        startOffset = (sel.value-1)*pageSize+1;\n");
    src.append("        if (searchName == null) searchName = '';\n");
    src.append("        InviteePickerDWRFacade.getGroupRecordsAndPageInfo(searchName,startOffset,pageSize,orderBy,req,{callback:function(data){eval('" + this.name + "_update_group_list(\\'' + tab_list_id + '\\',data,\\'' + searchName + '\\',\\'' + startOffset + '\\',\\'' + pageSize + '\\',\\'' + orderBy + '\\',\\'' + req + '\\')');},errorHandler:function(message){eval('timeOutError(message)');},timeout:10000});\n");
    src.append("        return null;\n");
    src.append("      }\n");
    
    src.append("      function " + this.name + "_role_page_select_change(tab_list_id,sel,searchName,startOffset,pageSize,orderBy,req){\n");
    src.append("        startOffset = (sel.value-1)*pageSize+1;\n");
    src.append("        if (searchName == null) searchName = '';\n");
    src.append("        InviteePickerDWRFacade.getRoleRecordsAndPageInfo(searchName,startOffset,pageSize,orderBy,req,{callback:function(data){eval('" + this.name + "_update_role_list(\\'' + tab_list_id + '\\',data,\\'' + searchName + '\\',\\'' + startOffset + '\\',\\'' + pageSize + '\\',\\'' + orderBy + '\\',\\'' + req + '\\')');},errorHandler:function(message){eval('timeOutError(message)');},timeout:10000});\n");
    src.append("        return null;\n");
    src.append("      }\n");

    src.append("      function " + this.name + "_filter_for_userView(ele,tab1_list_id,tab2_list_id,tab3_list_id) {\n");
    src.append("        var searchName = ele.value.replace(/\\'/gi,\"\\\\'\");\n");
    src.append("        var startOffset = 1;\n");
    src.append("        var pageSize = " + getListSize() + ";\n");
    src.append("        var orderBy_G = " + this.name + "userGOrderBy;\n");
    src.append("        var orderBy_R = " + this.name + "userROrderBy;\n");
    src.append("        var orderBy_S = " + this.name + "userSOrderBy;\n");
    src.append("        var req_G = " + this.name + "userGReq;\n");
    src.append("        var req_R = " + this.name + "userRReq;\n");
    src.append("        var req_S = " + this.name + "userSReq;\n");
    src.append("        var key_G = " + this.name + "KeyG;\n");
    src.append("        var key_R = " + this.name + "KeyR;\n");
    src.append("        var key_S = " + this.name + "KeyS;\n");
    src.append("        var hierarchy = " + this.name + "Hierarchy;\n");
    src.append("        InviteePickerDWRFacade.getUserRecordsAndPageInfo(searchName,'" + InviteesPickerManager.TYPE_GROUP + "',key_G,hierarchy,startOffset,pageSize,orderBy_G,req_G,{callback:function(data){eval('" + this.name + "_update_list(\\'" + this.name + "_group_user_list\\',data,searchName,\\'G\\',key_G,hierarchy,startOffset,pageSize,orderBy_G,req_G)');},errorHandler:function(message){eval('timeOutError(message)');},timeout:10000});\n");
    src.append("        InviteePickerDWRFacade.getUserRecordsAndPageInfo(searchName,'" + InviteesPickerManager.TYPE_ROLE + "',key_R,hierarchy,startOffset,pageSize,orderBy_R,req_R,{callback:function(data){eval('" + this.name + "_update_list(\\'" + this.name + "_role_user_list\\',data,searchName,\\'R\\',key_R,hierarchy,startOffset,pageSize,orderBy_R,req_R)');},errorHandler:function(message){eval('timeOutError(message)');},timeout:10000});\n");
    src.append("        InviteePickerDWRFacade.getUserRecordsAndPageInfo(searchName,'" + InviteesPickerManager.TYPE_GROUP + "',key_S,hierarchy,startOffset,pageSize,orderBy_S,req_S,{callback:function(data){eval('" + this.name + "_update_list(\\'" + this.name + "_staffhierarchy_user_list\\',data,searchName,\\'S\\',key_S,hierarchy,startOffset,pageSize,orderBy_S,req_S)');},errorHandler:function(message){eval('timeOutError(message)');},timeout:10000});\n");
    src.append("      }\n");
    
    src.append("      function " + this.name + "_filter_for_groupView(ele,tab_list_id) {\n");
    src.append("        var searchName = ele.value.replace(/\\'/gi,\"\\\\'\");\n");
    src.append("        var startOffset = 1;\n");
    src.append("        var pageSize = " + getListSize() + ";\n");
    src.append("        var orderBy = " + this.name + "groupOrderBy;\n");
    src.append("        var req = " + this.name + "groupReq;\n");
    src.append("        InviteePickerDWRFacade.getGroupRecordsAndPageInfo(searchName,startOffset,pageSize,orderBy,req,{callback:function(data){eval('" + this.name + "_update_group_list(\\'' + tab_list_id + '\\',data,\\'' + searchName + '\\',\\'' + startOffset + '\\',\\'' + pageSize + '\\',\\'' + orderBy + '\\',\\'' + req + '\\')');},errorHandler:function(message){eval('timeOutError(message)');},timeout:10000});\n");
    src.append("      }\n");
    
    src.append("      function " + this.name + "_filter_for_roleView(ele,tab_list_id) {\n");
    src.append("        var searchName = ele.value.replace(/\\'/gi,\"\\\\'\");\n");
    src.append("        var startOffset = 1;\n");
    src.append("        var pageSize = " + getListSize() + ";\n");
    src.append("        var orderBy = " + this.name + "roleOrderBy;\n");
    src.append("        var req = " + this.name+ "roleReq;\n");
    src.append("        InviteePickerDWRFacade.getRoleRecordsAndPageInfo(searchName,startOffset,pageSize,orderBy,req,{callback:function(data){eval('" + this.name + "_update_role_list(\\'' + tab_list_id + '\\',data,\\'' + searchName + '\\',\\'' + startOffset + '\\',\\'' + pageSize + '\\',\\'' + orderBy + '\\',\\'' + req + '\\')');},errorHandler:function(message){eval('timeOutError(message)');},timeout:10000});\n");
    src.append("      }\n");
    
    src.append("    //-->\n");
    src.append("    </script>\n");
    src.append("\n");

    return src.toString();
  }

  /**
   * render group view html.
   * @return                 String
   */
  public String renderTabGroupView(){
    StringBuffer src = new StringBuffer();

    src.append("    <div id='" + this.name + "_tab_group' class='form-inviteePicker-view-s'>\n");
    src.append("      <table cellpadding='0' cellspacing='0' width='100%' height='100%'>\n");
    src.append("      <tbody>\n");
    src.append("        <tr>\n");
    src.append("          <td>\n");
    src.append("            <table cellpadding='0' cellspacing='0' width='100%' height='100%'>\n");
    src.append("            <tbody>\n");
    src.append("              <tr>\n");
    src.append("                <td width='150'>\n");
    src.append("                  <div id='" + this.name + "_group_tree' noWrap class='form-inviteePicker-view-tree'>\n");
    src.append("                    <!-- innerHTML -->\n");
    src.append("                  </div>\n");
    src.append("                </td>\n");
    src.append("                <td>\n");
    src.append("                  <table>\n");
    src.append("                  <tbody>\n");
    src.append("                    <tr>\n");
    src.append("                      <td>\n");
    src.append("                        <div id='" + this.name + "_group_select_button' align='left' class='form-inviteePicker-view-buttonField'>                  \n");
    src.append("                          <table align='left' cellpadding='0' cellspacing='0' width='100%' height='100%' >\n");
    src.append("                          <tbody>\n");
    src.append("                            <tr>\n");
    src.append("                              <td align='left' valign='middle'>\n");
    src.append("                              <nobr>&nbsp;\n");
    src.append("                                <img src='" + WebUtil.getImage(pageContext.getRequest(), "ButtonSelectAll.gif", false)+"' onclick='" + this.name + "_GroupSelectAll()' style='cursor:pointer;' align=absMiddle border=0 />&nbsp;\n");
    src.append("                                <img src='" + WebUtil.getImage(pageContext.getRequest(), "ButtonSelectNone.gif", false)+"' onclick='" + this.name + "_GroupSelectNone()' style='cursor:pointer;' align=absMiddle border=0 />\n");
    src.append("                              </nobr>\n");
    src.append("                              </td>\n");
    src.append("                              <td width='100%'></td>\n");
    src.append("                            </tr>\n");
    src.append("                          </tbody>\n");
    src.append("                          </table>\n");
    src.append("                        </div>\n");
    src.append("                      </td>\n");
    src.append("                    </tr>\n");
    src.append("                    <tr>\n");
    src.append("                      <td>\n");
    src.append("                        <div id='" + this.name + "_group_user_list' class='form-inviteePicker-view-list'>\n");
    src.append("                          <!-- innerHTML -->\n");
    src.append("                        </div>\n");
    src.append("                      </td>\n");
    src.append("                    </tr>\n");
    src.append("                  </tbody>\n");
    src.append("                  </table>\n");
    src.append("                </td>\n");
    src.append("              </tr>\n");
    src.append("            </tbody>\n");
    src.append("            </table>\n");
    src.append("          </td>\n");
    src.append("        </tr>\n");
    src.append("      </tbody>\n");
    src.append("      </table>\n");
    src.append("    </div>\n");
    src.append("\n");
    
    return src.toString();
  }

  /**
   * render role view html.
   * @return                 String
   */
  public String renderTabRoleView(){
    StringBuffer src = new StringBuffer();

    src.append("    <div id='" + this.name + "_tab_role' class='form-inviteePicker-view-h'>\n");
    src.append("      <table cellpadding='0' cellspacing='0' width='100%' height='100%'>\n");
    src.append("      <tbody>\n");
    src.append("        <tr>\n");
    src.append("          <td>          \n");
    src.append("          <table cellpadding='0' cellspacing='0' width='100%' height='100%'>\n");
    src.append("            <tbody>\n");
    src.append("              <tr>\n");
    src.append("                <td width='150'>\n");
    src.append("                  <div id='" + this.name + "_role_tree' noWrap class='form-inviteePicker-view-tree'>\n");
    src.append("                    <!-- innerHTML -->\n");
    src.append("                  </div>\n");
    src.append("                </td>\n");
    src.append("                <td>\n");
    src.append("                  <table>\n");
    src.append("                  <tbody>\n");
    src.append("                    <tr>\n");
    src.append("                      <td>\n");
    src.append("                        <div id='" + this.name + "_role_select_button' align='left' class='form-inviteePicker-view-buttonField'>                 \n");
    src.append("                          <table align='left' cellpadding='0' cellspacing='0' width='100%' height='100%' >\n");
    src.append("                          <tbody>\n");
    src.append("                            <tr>\n");
    src.append("                              <td align='left' valign='middle'>\n");
    src.append("                              <nobr>&nbsp;\n");
    src.append("                                <img src='" + WebUtil.getImage(pageContext.getRequest(), "ButtonSelectAll.gif", false)+"' onclick='" + this.name + "_RoleSelectAll()' style='cursor:pointer;' align=absMiddle border=0 />&nbsp;\n");
    src.append("                                <img src='" + WebUtil.getImage(pageContext.getRequest(), "ButtonSelectNone.gif", false)+"' onclick='" + this.name + "_RoleSelectNone()' style='cursor:pointer;' align=absMiddle border=0 />\n");
    src.append("                              </nobr>\n");
    src.append("                              </td>\n");
    src.append("                              <td width='100%'></td>\n");
    src.append("                            </tr>\n");
    src.append("                          </tbody>\n");
    src.append("                          </table>\n");
    src.append("                        </div>\n");
    src.append("                      </td>\n");
    src.append("                    </tr>\n");
    src.append("                    <tr>\n");
    src.append("                      <td>\n");
    src.append("                        <div id='" + this.name + "_role_user_list' class='form-inviteePicker-view-list'>\n");
    src.append("                          <!-- innerHTML -->\n");
    src.append("                        </div>\n");
    src.append("                      </td>\n");
    src.append("                    </tr>\n");
    src.append("                  </tbody>\n");
    src.append("                  </table>\n");
    src.append("                </td>\n");
    src.append("              </tr>\n");
    src.append("            </tbody>\n");
    src.append("            </table>\n");
    src.append("          </td>\n");
    src.append("        </tr>\n");
    src.append("      </tbody>\n");
    src.append("      </table>\n");
    src.append("    </div>\n");
    src.append("\n");
    
    return src.toString();
  }

  /**
   * render staff hierarchy view html.
   * @return                 String
   */
  public String renderTabStaffHierarchyView(){
    StringBuffer src = new StringBuffer();

    src.append("    <div id='" + this.name + "_tab_staffhierarchy' class='form-inviteePicker-view-h'>\n");
    src.append("      <table cellpadding='0' cellspacing='0' width='100%' height='100%'>\n");
    src.append("      <tbody>\n");
    src.append("        <tr>\n");
    src.append("          <td>\n");
    src.append("          <table cellpadding='0' cellspacing='0' width='100%' height='100%'>\n");
    src.append("            <tbody>\n");
    src.append("              <tr>\n");
    src.append("                <td width='150'>\n");
    src.append("                  <div id='" + this.name + "_staffhierarchy_tree' noWrap class='form-inviteePicker-view-tree'>\n");
    src.append("                  <!-- innerHTML -->\n");
    src.append("                  </div>\n");
    src.append("                </td>\n");
    src.append("                <td>\n");
    src.append("                  <table>\n");
    src.append("                  <tbody>\n");
    src.append("                    <tr>\n");
    src.append("                      <td>\n");
    src.append("                        <div id='" + this.name + "_staffhierarchy_select_button' align='left' class='form-inviteePicker-view-buttonField'>                 \n");
    src.append("                          <table align='left' cellpadding='0' cellspacing='0' width='100%' height='100%' >\n");
    src.append("                          <tbody>\n");
    src.append("                            <tr>\n");
    src.append("                              <td align='left' valign='middle'>\n");
    src.append("                              <nobr>&nbsp;\n");
    src.append("                                <img src='" + WebUtil.getImage(pageContext.getRequest(), "ButtonSelectAll.gif", false)+"' onclick='" + this.name + "_StaffSelectAll()' style='cursor:pointer;' align=absMiddle border=0 />&nbsp;\n");
    src.append("                                <img src='" + WebUtil.getImage(pageContext.getRequest(), "ButtonSelectNone.gif", false)+"' onclick='" + this.name + "_StaffSelectNone()' style='cursor:pointer;' align=absMiddle border=0 />\n");
    src.append("                              </nobr>\n");
    src.append("                              </td>\n");
    src.append("                              <td width='100%'></td>\n");
    src.append("                            </tr>\n");
    src.append("                          </tbody>\n");
    src.append("                          </table>\n");
    src.append("                        </div>\n");
    src.append("                      </td>\n");
    src.append("                    </tr>\n");
    src.append("                    <tr>\n");
    src.append("                      <td>\n");
    src.append("                        <div id='" + this.name + "_staffhierarchy_user_list' class='form-inviteePicker-view-list'>\n");
    src.append("                          <!-- innerHTML -->\n");
    src.append("                        </div>\n");
    src.append("                      </td>\n");
    src.append("                    </tr>\n");
    src.append("                  </tbody>\n");
    src.append("                  </table>\n");
    src.append("                </td>\n");
    src.append("              </tr>\n");
    src.append("            </tbody>\n");
    src.append("            </table>\n");
    src.append("          </td>\n");
    src.append("        </tr>\n");
    src.append("      </tbody>\n");
    src.append("      </table>\n");
    src.append("    </div>\n");
    src.append("\n");

    return src.toString();
  }

  /**
   * render group/role/staff hierarchy view initialize javascript.
   * @return                 String
   */
  public String renderTabTreeInitJS(){
    StringBuffer src = new StringBuffer();

    src.append("    <script language='javascript'>\n");
    src.append("    <!--\n");
    src.append("      var " + this.name + "_firstOpenFlag = true;\n");
    src.append("      function " + this.name + "_popupUserBrowsering(){\n");
    src.append("        " + this.name + "_InitDialogCach();\n");
    src.append("        if (" + this.name + "_firstOpenFlag){\n");
    src.append("          InviteePickerDWRFacade.getGroupList({callback:function(data){eval('" + this.name + "_createGroupTree(\\'" + this.name + "_group_tree\\',data)');},errorHandler:function(message){eval('timeOutError(message)');},timeout:10000});\n");
    src.append("        } else {\n");
    src.append("          showDialog('" + this.name + "');\n");
    src.append("        }\n");
    src.append("      }\n");
    src.append("      function " + this.name + "_createGroupTree(groupTreeListID,groupList){\n");
    src.append("        var ht = [];\n");
    src.append("        ht.push(\"<div><img src='" + WebUtil.getImage(pageContext.getRequest(), "IconTreeRoot.gif")+"' align=absMiddle border=0 />&nbsp;<span style='cursor:pointer;' onclick=" + this.name + "_GroupTreeClick('" + this.name + "',this,'" + InviteesPickerManager.TYPE_GROUP + "',null,null,1," + this.pageOffset + ",'FULL_NAME','ASC') >Group</span></div>\");\n");
    src.append("        for (var i=0;i<groupList.length;i++){\n");
    src.append("          if (i+1==groupList.length){\n");
    src.append("            ht.push(\"<div><img src='" + WebUtil.getImage(pageContext.getRequest(), "IconTreeL.gif")+"' align=absMiddle border=0 /><img src='" + WebUtil.getImage(pageContext.getRequest(), "IconGroup.gif")+"' align=absMiddle border=0 />&nbsp;<span style='cursor:pointer;' onclick=" + this.name + "_GroupTreeClick('" + this.name + "',this,'" + InviteesPickerManager.TYPE_GROUP + "','\" + groupList[i][0] + \"',null,1," + this.pageOffset + ",'FULL_NAME','ASC') >\" + groupList[i][1] + \"</span></div>\");\n");
    src.append("          } else {\n");
    src.append("            ht.push(\"<div><img src='" + WebUtil.getImage(pageContext.getRequest(), "IconTreeT.gif")+"' align=absMiddle border=0 /><img src='" + WebUtil.getImage(pageContext.getRequest(), "IconGroup.gif")+"' align=absMiddle border=0 />&nbsp;<span style='cursor:pointer;' onclick=" + this.name + "_GroupTreeClick('" + this.name + "',this,'" + InviteesPickerManager.TYPE_GROUP + "','\" + groupList[i][0] + \"',null,1," + this.pageOffset + ",'FULL_NAME','ASC') >\" + groupList[i][1] + \"</span></div>\");\n");
    src.append("          }\n");
    src.append("        }\n");
    src.append("        document.getElementById(groupTreeListID).innerHTML = ht.join('');\n");
    src.append("        InviteePickerDWRFacade.getRoleList({callback:function(data){eval('" + this.name + "_createRoleTree(\\'" + this.name + "_role_tree\\',data)');},errorHandler:function(message){eval('timeOutError(message)');},timeout:10000});\n");
    src.append("      }\n");
    src.append("      function " + this.name + "_createRoleTree(roleTreeListID,roleList){\n");
    src.append("        var ht = [];\n");
    src.append("        ht.push(\"<div><img src='" + WebUtil.getImage(pageContext.getRequest(), "IconTreeRoot.gif")+"' align=absMiddle border=0 />&nbsp;<span style='cursor:pointer;' onclick=" + this.name + "_RoleTreeClick('" + this.name + "',this,'" + InviteesPickerManager.TYPE_ROLE + "','','',1," + this.pageOffset + ",'FULL_NAME','ASC') >Role</span></div>\");\n");
    src.append("        for (var i=0;i<roleList.length;i++){\n");
    src.append("          if (i+1==roleList.length){\n");
    src.append("            ht.push(\"<div><img src='" + WebUtil.getImage(pageContext.getRequest(), "IconTreeL.gif")+"' align=absMiddle border=0 /><img src='" + WebUtil.getImage(pageContext.getRequest(), "IconRole.gif")+"' align=absMiddle border=0 />&nbsp;<span style='cursor:pointer;' onclick=" + this.name + "_RoleTreeClick('" + this.name + "',this,'" + InviteesPickerManager.TYPE_ROLE + "','\" + roleList[i][0] + \"','',1," + this.pageOffset + ",'FULL_NAME','ASC') >\" + roleList[i][1] + \"</span></div>\");\n");
    src.append("          } else {\n");
    src.append("            ht.push(\"<div><img src='" + WebUtil.getImage(pageContext.getRequest(), "IconTreeT.gif")+"' align=absMiddle border=0 /><img src='" + WebUtil.getImage(pageContext.getRequest(), "IconRole.gif")+"' align=absMiddle border=0 />&nbsp;<span style='cursor:pointer;' onclick=" + this.name + "_RoleTreeClick('" + this.name + "',this,'" + InviteesPickerManager.TYPE_ROLE + "','\" + roleList[i][0] + \"','',1," + this.pageOffset + ",'FULL_NAME','ASC') >\" + roleList[i][1] + \"</span></div>\");\n");
    src.append("          }\n");
    src.append("        }\n");
    src.append("        document.getElementById(roleTreeListID).innerHTML = ht.join('');\n");
    src.append("        InviteePickerDWRFacade.getStaffHierarchyList({callback:function(data){eval('" + this.name + "_createStaffHierarchyTree(\\'" + this.name + "_staffhierarchy_tree\\',data)');},errorHandler:function(message){eval('timeOutError(message)');},timeout:10000});\n");
    src.append("      }\n");
    src.append("      function " + this.name + "_createStaffHierarchyTree(staffHierarchyTreeListID,staffHierarchyList){\n");
    src.append("        webFXTreeConfig.folderIcon = '" + WebUtil.getImage(pageContext.getRequest(), "IconTreeStaff.gif")+"';\n");
    src.append("        webFXTreeConfig.openFolderIcon = '" + WebUtil.getImage(pageContext.getRequest(), "IconTreeStaff.gif")+"';\n");
    src.append("        var node0 = new WebFXTree('Staff Hierarchy', \"javascript:" + this.name + "_StaffTreeClick(\'" + this.name + "\',this,\'S\',\'\',\'\',1," + this.pageOffset + ",\'FULL_NAME\',\'ASC\')\", '0');\n");
    src.append("        node0.setBehavior('explorer');\n");
    src.append("        var grandParentID = 0;\n");
    src.append("        for (var i=1;i<=staffHierarchyList.length;++i){\n");
    src.append("          var level = parseInt(staffHierarchyList[i-1][2]);\n");
    src.append("          if (staffHierarchyList[i-1][0]==grandParentID) {\n");
    src.append("            grandParentID = parseInt(staffHierarchyList[i-1][3]);\n");
    src.append("          }\n");
    src.append("          if (level<=" + SystemParameterFactory.getSystemParameter(SystemParameterConstant.STAFF_HIERARCHY_LEVEL) + "){\n");
    src.append("            eval(\"var node\" + staffHierarchyList[i-1][0] + \" = new WebFXTreeItem('\" + staffHierarchyList[i-1][1].replace(/\\'/gi,\"\\\\'\") + \"',\\\"javascript:" + this.name + "_StaffTreeClick('" + this.name + "',this,'" + InviteesPickerManager.TYPE_HIERARCHY + "','\" + staffHierarchyList[i-1][0] + \"','LVL\" + level + \"_NAME',1," + this.pageOffset + ",'FULL_NAME','ASC')\\\",'0');\");\n");
    src.append("          }\n");
    src.append("        }\n");
    src.append("        for (var i=1;i<=staffHierarchyList.length;++i){\n");
    src.append("          if ( eval(\"typeof node\" + staffHierarchyList[i-1][3] + \"!= 'undefined'\") ) {\n");
    src.append("            eval(\"node\" + staffHierarchyList[i-1][3] + \".add( node\" + staffHierarchyList[i-1][0] + \")\");\n");
    src.append("          }\n");
    src.append("        }\n");
    src.append("        document.getElementById(staffHierarchyTreeListID).innerHTML = node0;\n");
    
    src.append("        InviteePickerDWRFacade.getUserRecordsAndPageInfo('" + InviteesPickerManager.TYPE_GROUP + "','','','1','" + this.pageOffset + "','FULL_NAME','ASC',{callback:function(data){eval('" + this.name + "_update_list(\\'" + this.name + "_group_user_list\\',data,\\'G\\',\\'\\',\\'\\',\\'1\\',\\'" + this.pageOffset + "\\',\\'FULL_NAME\\',\\'ASC\\')');},errorHandler:function(message){eval('timeOutError(message)');},timeout:10000});\n");
    src.append("        InviteePickerDWRFacade.getUserRecordsAndPageInfo('" + InviteesPickerManager.TYPE_ROLE + "','','','1','" + this.pageOffset + "','FULL_NAME','ASC',{callback:function(data){eval('" + this.name + "_update_list(\\'" + this.name + "_role_user_list\\',data,\\'R\\',\\'\\',\\'\\',\\'1\\',\\'" + this.pageOffset + "\\',\\'FULL_NAME\\',\\'ASC\\')');},errorHandler:function(message){eval('timeOutError(message)');},timeout:10000});\n");
    src.append("        InviteePickerDWRFacade.getUserRecordsAndPageInfo('" + InviteesPickerManager.TYPE_GROUP + "','','','1','" + this.pageOffset + "','FULL_NAME','ASC',{callback:function(data){eval('" + this.name + "_update_list(\\'" + this.name + "_staffhierarchy_user_list\\',data,\\'S\\',\\'\\',\\'\\',\\'1\\',\\'" + this.pageOffset + "\\',\\'FULL_NAME\\',\\'ASC\\')');},errorHandler:function(message){eval('timeOutError(message)');},timeout:10000});\n");
    src.append("        showDialog('" + this.name + "');\n");
    src.append("        " + this.name + "_firstOpenFlag = false;\n");
    src.append("      }\n");
    src.append("    //-->\n");
    src.append("    </script>\n");
    src.append("\n");
    
    return src.toString();
  }

  /**
   * render form button html.
   * @return                 String
   */
  public String renderButtonBar(){
    StringBuffer src = new StringBuffer();

    src.append("    <table cellpadding='0' cellspacing='0' width='100%' height='40'>\n");
    src.append("    <tbody>\n");
    src.append("      <tr>\n");
    src.append("        <td width='100%'></td>\n");
    src.append("        <td valign='middle'>\n");
    src.append("          &nbsp;<img src='" + WebUtil.getImage(pageContext.getRequest(), "ButtonConfirm.gif", false)+"' onclick=" + this.name + "_confirm('" + this.name + "')  style='cursor:pointer;' align=absMiddle border=0 />&nbsp;\n");
    src.append("        </td>\n");
    src.append("        <td valign='middle'>\n");
    src.append("          &nbsp;<img src='" + WebUtil.getImage(pageContext.getRequest(), "ButtonReset.gif", false)+"' onclick=" + this.name + "_reset('" + this.name + "')   style='cursor:pointer;' align=absMiddle border=0 />&nbsp;\n");
    src.append("        </td>\n");
    src.append("        <td valign='middle'>\n");
    src.append("          &nbsp;<img src='" + WebUtil.getImage(pageContext.getRequest(), "ButtonClose.gif", false)+"' onclick=\"" + this.name + "_ReleaseCache();hideDialog('" + this.name + "')\" style='cursor:pointer;' align=absMiddle border=0  />&nbsp;\n");
    src.append("        </td>\n");
    src.append("        <td>&nbsp;&nbsp;</td>\n");
    src.append("      </tr>\n");
    src.append("    </tbody>\n");
    src.append("    </table>\n");
    src.append("\n");
    
    return src.toString();
  }
  
  
  public int getListSize() {
    return listSize;
  }

  public void setListSize(int listSize) {
    if (listSize<=0){
      this.listSize = 10;
    } else {
      this.listSize = listSize;
    }
  }

  public String getName() {
    return name;
  }

  public void setName(String name) {
    this.name = name;
  }

  public String getPropertyGroup() {
    return propertyGroup;
  }

  public void setPropertyGroup(String propertyGroup) {
    this.propertyGroup = propertyGroup;
  }

  public String getPropertyRole() {
    return propertyRole;
  }

  public void setPropertyRole(String propertyRole) {
    this.propertyRole = propertyRole;
  }

  public String getPropertyUser() {
    return propertyUser;
  }

  public void setPropertyUser(String propertyUser) {
    this.propertyUser = propertyUser;
  }

  public String[] getValueGroup() {
    return valueGroup;
  }

  public void setValueGroup(String[] valueGroup) {
    this.valueGroup = valueGroup;
  }

  public String[] getValueRole() {
    return valueRole;
  }

  public void setValueRole(String[] valueRole) {
    this.valueRole = valueRole;
  }

  public String[] getValueUser() {
    return valueUser;
  }

  public void setValueUser(String[] valueUser) {
    this.valueUser = valueUser;
  }

  public String getContextPath() {
    return contextPath;
  }

  public void setContextPath(String contextPath) {
    this.contextPath = contextPath;
  }

  public String getHeight() {
    return height;
  }

  public void setHeight(String height) {
    this.height = height;
  }

  public String getWidth() {
    return width;
  }

  public void setWidth(String width) {
    this.width = width;
  }

  public String getSuggestWidth() {
    return suggestWidth;
  }

  public void setSuggestWidth(String suggestWidth) {
    this.suggestWidth = suggestWidth;
  }

  public String getTextWidth() {
    return textWidth;
  }

  public void setTextWidth(String textWidth) {
    this.textWidth = textWidth;
  }

  public Connection getConnection(HttpServletRequest request) {
    return((Connection)request.getAttribute(GlobalConstant.DB_KEY));
  }

  public boolean isEnableGroup() {
    return enableGroup;
  }

  public void setEnableGroup(boolean enableGroup) {
    this.enableGroup = enableGroup;
  }
  
  public boolean isEnableRole() {
    return enableRole;
  }

  public void setEnableRole(boolean enableRole) {
    this.enableRole = enableRole;
  }

  public boolean isEnableUser() {
    return enableUser;
  }

  public void setEnableUser(boolean enableUser) {
    this.enableUser = enableUser;
  }

  public boolean isEnableUserBrowsering() {
    return enableUserBrowsering;
  }

  public void setEnableUserBrowsering(boolean enableUserBrowsering) {
    this.enableUserBrowsering = enableUserBrowsering;
  }

  public Integer getMaxLength() {
    return maxLength;
  }

  public void setMaxLength(Integer maxLength) {
    this.maxLength = maxLength;
  }

}
